const superagent = require("superagent");
const cheerio = require("cheerio");
const baseUrl = "http://music.163.com";
function getPlayList(success, fail,offset = 0) {
    let getData = {
        order: "hot",
        cat: "%25E5%2585%25A8%25E9%2583%25A8",
        limit: 35,
        offset: offset
    };
    superagent
        .get(baseUrl + "/discover/playlist")
        .query(getData)
        .then(res => {
            let $ = cheerio.load(res.text);
            let list = $("#m-pl-container li");
            let listInfo = [];
            for (let i = 0; i < list.length; i++) {
                let musicPlayListObj = {
                    imgSrc: list
                        .eq(i)
                        .find(".j-flag")
                        .attr("src"),
                    title: list
                        .eq(i)
                        .find(".msk")
                        .attr("title"),
                    href:
                        baseUrl +
                        list
                            .eq(i)
                            .find(".msk")
                            .attr("href"),
                    playNum: list
                        .eq(i)
                        .find(".nb")
                        .text()
                };
                listInfo.push(musicPlayListObj);
            }
            success(listInfo);
        })
        .catch(error => {
            fail(error);
        });
}
module.exports=getPlayList;